<%@page import="support.*, java.util.*, java.sql.*" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Submit Application</title>
</head>
<body>

<%

	Connection conn = null;
	PreparedStatement stm = null;
	ResultSet result = null;
	
	try {
		Class.forName("org.postgresql.Driver");
		conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/Graduate_application_database", "postgres", "postgres");

		Student student = (Student)session.getAttribute("student");
		ArrayList<Degree> degreeList = (ArrayList<Degree>)session.getAttribute("degreelist");
    	if (request.getParameter("specialization") != null)
        	student.specialization(Integer.parseInt(request.getParameter("specialization")));
       
%>

	<h3>Previously entered in information:</h3>

	<p><%= "Full name: " + student.getFirstName() + " " + student.getMiddleName() + " " + student.getLastName() %></br>
	<%= "Country of Citizenship: " + student.getCitizenshipName() %></br>
	<% if (student.getState() != "") { %>
		<%= "Address: " + student.getAddress() + ", " + student.getCity() + " " + student.getState() + ", " + student.getZipcode() %>
	<% } else {%>
		<%= "Address: " + student.getAddress() + ", " + student.getCity() + ", " + student.getZipcode() %></p>
	<% } %>
	
	<%
   //Print out degree information if coming from more degrees
   if (degreeList != null) {
      for (int i = 0; i < degreeList.size(); i++) {
%>
         <p><b><%= "Degree #" + (i+1) + ": " %></b><br>
         <%= degreeList.get(i).getDisciplineName() + ", " + degreeList.get(i).getTitle() %><br> 
         <%= degreeList.get(i).getUniversityName() %><br>
         <%= degreeList.get(i).getLocationName() %><br>
         <%= "Year of Graduation: " + degreeList.get(i).getDate() %><br>
         <%= "GPA: " + degreeList.get(i).getGpa() %><br>
<%
	   }	   
   }
%>

<%
	conn.setAutoCommit(false);
	stm = conn.prepareStatement("SELECT specialization FROM specializations WHERE s_id = ? ");
	stm.setInt(1, student.getSpecialization());
	result = stm.executeQuery();
	result.next();

	conn.commit();
	conn.setAutoCommit(true);
%>

<p>Specialization: <%= result.getString("specialization") %></p>


<h3>Submit Application?</h3>

   <form method="GET" action="confirmation.jsp">
   <input type="submit" value="Submit Application"/> 
   </form>

   <form method="GET" action="verification.jsp">
   <input type="submit" value="Cancel"/> 
   </form>

<% 
		result.close();
		stm.close();
		conn.close();
	}
	catch (SQLException e)
	{
		throw new RuntimeException(e);
	}
    finally {
        if (result != null) {
            try {
                result.close();
            } 
            catch (SQLException e) { }
            result = null;
        }
        if (stm != null) {
            try {
                stm.close();
            } 
            catch (SQLException e) { }
            stm = null;
        }
        if (conn != null) {
            try {
                conn.close();
            } 
            catch (SQLException e) { }
            conn = null;
        }
    }
%>	

</body>
</html>